package com.tanker.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author xqxue
 * @time 2018年7月20日 下午2:32:27
 */
public class SignUtils {

	private final static String ctrip_key = "";
	private final static String ctrip_secret = "";
	
	/**
	 * 生成携程签名
	 */
	public static String generateSign(Map<String, String> parameter, long requestTime){
		List<String> keys = new ArrayList<String>();
		keys.addAll(parameter.keySet());
		Collections.sort(keys);
		
		StringBuffer sb = new StringBuffer();
		sb.append(ctrip_key);
		sb.append(ctrip_secret);
		sb.append(requestTime+"");
		for (String k : keys) {
			sb.append(k).append("=").append(parameter.get(k)).append("&");
        }
		sb.replace(sb.length()-1, sb.length(), "");
		String sign = MD5.sign(sb.toString());
		
		return sign;
	}
}
